# 7-6 集合元素删除【组合数据类型】
n_list = list(map(int, input().split()))
N = int(input())

s = set(n_list)

for _ in range(N):
    command = input().split()
    if command[0] == 'pop':
        if s:
            s.pop()
    elif command[0] == 'remove':
        if int(command[1]) in s:
            s.remove(int(command[1]))
    elif command[0] == 'discard':
        s.discard(int(command[1]))

print(sum(s))